﻿<UserControl
			 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
			 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
			 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
			 xmlns:local="clr-namespace:ERDDiagram"
			 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
			 xmlns:sd="http://schemas.silverdiagram.net/sd/2010/xaml"
			 xmlns:shapesBasic="clr-namespace:SD.Shapes.Templates.Basic;assembly=SD.Shapes.Templates.Basic"
			 xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
			 xmlns:localShapes="clr-namespace:ERDDiagram"
			 xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
			 xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"            
			 xmlns:ERDDiagram_Helpers="clr-namespace:ERDDiagram.Helpers" x:Class="ERDDiagram.MainPage"
			 mc:Ignorable="d"
			 d:DesignHeight="607" Height="Auto" Name="page" SizeChanged="page_SizeChanged">

    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Skins/MainSkin.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <UserControl.DataContext>
        <Binding Path="Main" Source="{StaticResource Locator}"/>
    </UserControl.DataContext>
    <toolkit:BusyIndicator  IsBusy="{Binding IsBusy, Mode=TwoWay}" BusyContent="Searching ..." 
							   DataContext="{Binding}" HorizontalAlignment="Center"  VerticalAlignment="Top" Name="bsyIndicator" >
        <Grid x:Name="LayoutRoot"  Width="{Binding Path=LayoutrootActualWidth, Mode=TwoWay}" Height="{Binding Path=LayoutrootActualHeight, Mode=TwoWay}" >
            <Grid.RowDefinitions>
                <RowDefinition Height="130"  />
                <RowDefinition Height="500*" MinHeight="100"  />
            </Grid.RowDefinitions>
            <Grid Visibility="{Binding WarningMessage}">
                <TextBlock Text="Please enter a name and save the diagram record first."></TextBlock>
            </Grid>
            <toolkit:Expander Grid.Row="0"  Margin="0" Visibility="{Binding DiagramDisplay}" Style="{StaticResource ExpanderFadeStyle}" Name="Expander1"
                              ExpandDirection="Down" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed"
                               >
                <toolkit:Expander.Header>                    
                        <Grid x:Name="NavigationGrid" Style="{StaticResource NavigationGridStyle}" Visibility="{Binding DiagramDisplay}" >
                            <Border x:Name="BrandingBorder" Style="{StaticResource BrandingBorderStyle}" HorizontalAlignment="Left" Margin="0,0,0,0" Width="{Binding Path=LayoutrootActualWidth, Mode=TwoWay}">
                                <StackPanel x:Name="BrandingStackPanel" Style="{StaticResource BrandingStackPanelStyle}">
                                    <ContentControl Style="{StaticResource LogoIcon}"/>
                                    <TextBlock x:Name="ApplicationNameTextBlock" Style="{StaticResource ApplicationNameStyle}" Text="{Binding WelcomeTitle}" Width="200"/>
                                </StackPanel>
                            </Border>
                            <Border x:Name="LinksBorder" Style="{StaticResource LinksBorderStyle}" HorizontalAlignment="Right">
                                <StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}">
                                    <HyperlinkButton x:Name="Link2" Style="{StaticResource LinkStyle}" 
                                      Command="{Binding ShowAbout}" TargetName="ContentFrame" Content="About" HorizontalAlignment="Right"/>
                                </StackPanel>
                            </Border>
                        </Grid>                    
                </toolkit:Expander.Header>                
                <toolkit:Expander.Content>                        
                    <StackPanel>
                        <Grid Visibility="{Binding DiagramDisplay}">
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition />
                                <ColumnDefinition Width="128" />
                                <ColumnDefinition Width="78" />
                                <ColumnDefinition Width="70" />
                                <ColumnDefinition Width="71" />
                                <ColumnDefinition Width="12.5" />
                            </Grid.ColumnDefinitions>

                            <Grid HorizontalAlignment="Stretch"  Margin="0,0,10,0" Grid.ColumnSpan="2">
                                <Grid.ColumnDefinitions >
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition  />
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Text="Select Solution" />
                                <ComboBox x:Name="SolutionsComboBox" Grid.Column="1" HorizontalAlignment="Stretch"  VerticalAlignment="Center" 
						  ItemsSource="{Binding SolutionList, Mode=OneWay}" DisplayMemberPath="SolutionName" SelectedValuePath="SolutionId" 
						  SelectedItem="{Binding SelectedSolution, Mode=TwoWay}" DataContext="{Binding}" Margin="0,6,12,0" Height="Auto" >
                                    <i:Interaction.Behaviors>
                                        <ERDDiagram_Helpers:KeyboardSelectionBehavior SelectionMemberPath="TypeName"/>
                                    </i:Interaction.Behaviors>
                                </ComboBox>
                            </Grid>
                            <Button Content="Generate from Solution" Grid.Column="2" Height="23" HorizontalAlignment="Left" Margin="0,3,0,0"  VerticalAlignment="Top" Width="140" Command="{Binding GenerateDiagramFromSolution}" d:LayoutOverrides="GridBox" Grid.ColumnSpan="2" />
                            <Button Content="Export" Height="23" HorizontalAlignment="Left" Margin="1.5,3,0,0" x:Name="ExportButton" VerticalAlignment="Top" Width="61" Grid.Column="4" RenderTransformOrigin="0.68,0.565" Click="ExportButton_Click" />
                        </Grid>
                        <Grid  Visibility="{Binding DiagramDisplay}">
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition />
                                <ColumnDefinition Width="128" />
                                <ColumnDefinition Width="78" />
                                <ColumnDefinition Width="70" />
                                <ColumnDefinition Width="71" />
                                <ColumnDefinition Width="12.5" />
                            </Grid.ColumnDefinitions>

                            <Grid HorizontalAlignment="Stretch"  Margin="0,0,10,0" Grid.ColumnSpan="2">
                                <Grid.ColumnDefinitions >
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition  />
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Text="Select Type" />
                                <ComboBox x:Name="EntityTypesComboBox" Grid.Column="1" HorizontalAlignment="Stretch"  VerticalAlignment="Center" 
						  ItemsSource="{Binding EntityTypeList, Mode=OneWay}" DisplayMemberPath="TypeName" SelectedValuePath="TypeName" 
						  SelectedItem="{Binding SelectedEntityType, Mode=TwoWay}" DataContext="{Binding}" Margin="0,6,12,0" Height="Auto" >
                                    <i:Interaction.Behaviors>
                                        <ERDDiagram_Helpers:KeyboardSelectionBehavior SelectionMemberPath="TypeName"/>
                                    </i:Interaction.Behaviors>
                                </ComboBox>
                            </Grid>
                            <Button Content="Zoom -" Grid.Column="2" Height="23" HorizontalAlignment="Left" Margin="0,3,0,0" x:Name="ZoomLessButton" VerticalAlignment="Top" Width="72" Command="{Binding ZoomLessCommand}" d:LayoutOverrides="GridBox" />
                            <Button Content="Zoom +" Grid.Column="3" Height="23" HorizontalAlignment="Left" x:Name="ZoomPlusButton" VerticalAlignment="Top" Width="61" Command="{Binding ZoomPlusComand}" Margin="1.5,3,0,0" />
                            <Button Content="Save" Grid.Column="4" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" Width="61" Command="{Binding SaveDiagram}" Margin="1.5,3,0,0" />
                        </Grid>
                        <Grid  Visibility="{Binding DiagramDisplay}">
                            <Grid.ColumnDefinitions >
                                <ColumnDefinition />
                                <ColumnDefinition Width="128" />
                                <ColumnDefinition Width="78" />
                                <ColumnDefinition Width="70" />
                                <ColumnDefinition Width="71" />
                                <ColumnDefinition Width="12.5" />
                            </Grid.ColumnDefinitions>

                            <Grid HorizontalAlignment="Stretch" Margin="0,0,10,0" Grid.ColumnSpan="2">
                                <Grid.ColumnDefinitions >
                                    <ColumnDefinition Width="120" />
                                    <ColumnDefinition  />
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Left" FontWeight="Bold" Text="Select Entity" />
                                <ComboBox x:Name="EntityComboBox" Grid.Column="1" HorizontalAlignment="Stretch"  VerticalAlignment="Center"
						  ItemsSource="{Binding EntityList, Mode=OneWay}" DisplayMemberPath="SchemaNameSet" SelectedValuePath="LogicalName" 
                              SelectedItem="{Binding SelectedEntity, Mode=TwoWay}" DataContext="{Binding}" Margin="0,6,12,0"  Height="Auto">
                                    <i:Interaction.Behaviors>
                                        <ERDDiagram_Helpers:KeyboardSelectionBehavior SelectionMemberPath="SchemaNameSet"/>
                                    </i:Interaction.Behaviors>
                                </ComboBox>
                            </Grid>
                            <Button Content="Add" Height="23" HorizontalAlignment="Left" Margin="0,3,0,0" x:Name="button1" VerticalAlignment="Top" Width="72" IsEnabled="{Binding IsAllowedToGenerate}" Command="{Binding AddEntity_Click}" Grid.Column="2" />
                            <Button Content="Print" x:Name="printButton" HorizontalAlignment="Left" Height="23" Grid.Column="3" Margin="1.5,3,0,0"  Click="printButton_Click"  Width="61" VerticalAlignment="Top" />
                            <Button Content="Clear" Height="23" HorizontalAlignment="Left" Margin="1.5,3,0,0" x:Name="clearButton" VerticalAlignment="Top" Width="61" Grid.Column="4"  Command="{Binding ClearEntities_Click}" RenderTransformOrigin="0.68,0.565"/>
                        </Grid>
                    </StackPanel>
                </toolkit:Expander.Content>
            </toolkit:Expander>
            <Grid Grid.Row="1">
                <ScrollViewer Height="Auto" Width="Auto" x:Name="ScrViewer"  Visibility="{Binding DiagramDisplay}"
				  HorizontalScrollBarVisibility="{Binding Path=HorizontalScrollBarVisibility, Mode=TwoWay}" 
					  VerticalScrollBarVisibility="{Binding Path=VerticalScrollVisibility, Mode=TwoWay}" Grid.Row="3" 
				  local:ScrollViewerBinding.VerticalOffset="{Binding ScrollVerticalOffset, Mode=TwoWay}"
				  local:ScrollViewerBinding.HorizontalOffset="{Binding ScrollHorizontalOffset, Mode=TwoWay}"                      
				  Background="Gray">
                    <Grid x:Name="Layoutroot3" Background="White" Visibility="{Binding DiagramDisplay}"      
                          Width="{Binding Path=LayoutrootWidth,Mode=TwoWay}"
                          Height="{Binding Path=LayoutrootHeight,Mode=TwoWay}">
                        <Canvas x:Name="LayoutRoot2" Background="White" 
						 ScrollViewer.HorizontalScrollBarVisibility="Visible"
						ScrollViewer.VerticalScrollBarVisibility="Visible">
                            <Canvas.RenderTransform>
                                <ScaleTransform x:Name="stCurrentZoom" ScaleX="{Binding ZoomScaleX, Mode=TwoWay}" ScaleY="{Binding ZoomScaleY, Mode=TwoWay}"/>
                            </Canvas.RenderTransform>
                            <sd:Diagram Background="Transparent" SelectedItem="{Binding Path=SelectedDiagramItem, Mode=TwoWay}" ItemsSource="{Binding MyEntityList}"
							VerticalAlignment="Top" x:Name="myDiagram" VerticalContentAlignment="Stretch"  >
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MouseLeftButtonUp">
                                        <ei:CallMethodAction MethodName="NodePositionChanged" TargetObject="{Binding}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </sd:Diagram>
                        </Canvas>
                    </Grid>
                </ScrollViewer>
            </Grid>
        </Grid>
    </toolkit:BusyIndicator>
</UserControl>
